<%--
  Created by IntelliJ IDEA.
  User: jia19
  Date: 2015/10/5
  Time: 22:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
<head>
    <title>后台管理系统——图书管理</title>
    <%@ include file="../../layout/import.jsp"%>
    <script type="text/javascript">
        function delBook(bookid) {
            if(confirm("确定删除吗？删除后不可恢复！")){
                $.ajax({
                    url: "/admin/delBook.do",
                    data: {id:bookid},
                    method: "POST",
                    dataType: "json",
                    error: function () {
                        alert("表单提交出错，请稍后再试");
                    },
                    success: function(response) {
                        if(response.code == 0) {
                            alert("删除成功");
                            window.location.href = "/admin/book.do";

                        }
                        else {
                            alert(response.description);
                        }
                    }
                });
            }
        }
    </script>
</head>
<body>
<%@ include file="nav.jsp"%>

<div class="container" style="min-height: 72%">
    <div class="col-sm-12">
        <a class="btn btn-primary" href="/admin/newBook.do">新书入库</a>
        <br /><br />
        <table class="table table-hover">
            <tr>
                <th>ISBN</th><th>书名</th><th>作者</th><th>出版社</th><th>价格</th><th>库存</th><th>存储位置</th><th>分类</th><th>操作</th>
            </tr>

            <c:forEach var="book" items="${bookList}">
                <tr>
                    <td>${book.isbn}</td><td>${book.bookname}</td><td>${book.author}</td>
                    <td>${book.publisherid}</td><td>${book.price}</td><td>${book.quantity}</td>
                    <td>${book.place}</td><td>${book.category}</td>
                    <td>
                        <a href="/admin/bookEdit.do?id=${book.id}">编辑</a>
                        <a onclick="delBook(${book.id})">删除</a>
                    </td>
                </tr>
            </c:forEach>

        </table>

        <nav>
            <ul class="pagination">
                <!--
                <li <c:if test="${thisPage eq 1}">class="disabled"</c:if> >
                    <a href="/admin/book.do?page=${thisPage - 1}" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                -->
                <c:forEach var="page" begin="1" end="${totalPage}" step="1" >
                    <li <c:if test="${thisPage eq page}">class="active"</c:if> ><a href="/admin/book.do?page=${page}" > ${page}</a></li>
                </c:forEach>
                <!--
                <li <c:if test="${thisPage eq totalPage}">class="disabled"</c:if>>
                    <a href="/admin/book.do?page=${thisPage + 1}" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
                -->
            </ul>
        </nav>

    </div>

</div>


<%@ include file="../footer.jsp"%>
</body>
</html>
